<script>
var expandedId = null, loading = false;
window.funcLoadStatistic = function(id, ajaxUrl, data, open) {
  if (loading) {
    return;
  }
  var dTr;
  if (expandedId ) {
    dTr = $('#table > tbody > tr[data-id="' + expandedId + '"]');
    dTr.children('td:eq(0)').removeAttr('rowspan');
    dTr.next().remove();
    if (expandedId == id) {
      expandedId = null;
      if (!open) {
        return;
      }
    }
    expandedId = null;
  }
  loading = true;
  dTr = $('#table > tbody > tr[data-id="' + id + '"]');
  dTr.children('td:eq(0)').attr('rowspan', 2);
  dTr.after(
    `<tr class="statics" statics-id="' + id + '"><td colspan="7">
      <section class="widget">
      <header id="widget-header" class="mb-sm" style="margin-bottom: 5px;">
        <div class="clearfix mb-xs">
          <div class="btn-group pull-left">
          </div>
        </div>
      </header>
      <div class="widget-table-overflow">
        <table class="table table-striped table-bordered table-hover dataTable">
        <thead><tr>
          <th width="140" class="center">操作</th>
          <th width="80" class="center">期初鲜花</th>
          <th width="80" class="center">鲜花变动</th>
          <th width="80" class="center">期末鲜花</th>
          <th width="120" class="center">操作时间</th>
          <th class="center">备注</th>
        </tr></thead>
        <tbody class="pointer">
          <tr><td colspan="6">
            <div class="center" style="line-height:100px">
            <span class="color-red"><i class="icon-spinner icon-spin orange bigger-125"></i> 正在加载中...</span>
            </div>
          </td></tr>
        </tbody>
        </table>
      </div>
      </section>
    </td></tr>`);
  var funcLoad = function(url) {
    dTr.next().find('td > div').html('<span class="color-red"><i class="icon-spinner icon-spin orange bigger-125"></i> 正在加载中...</span>')
    $.ajax(url, {
      type: 'GET',
      dataType: 'JSON'
    }).done(function(result) {
        result = result.result;
        let page = result.page, count = result.count, rows = result.rows,
            pageUrl = /[^\?]+/.exec(url)[0]  + '?page=%page%';
        let resultData = result.list, html = [], i;
        let op, oflowers, nflowers, created, message, className;
        if (resultData && resultData[0]) {
          for (i = 0; i < resultData.length; i++) {
            op = resultData[i].op;
            oflowers = resultData[i].oflowers.toString().split('.')[0];
            flowers = resultData[i].flowers.toString().split('.')[0];
            className = flowers < 0 ? 'danger': 'success';
            nflowers = resultData[i].nflowers.toString().split('.')[0];
            message = resultData[i].message;
            created = new Date(resultData[i].created * 1000).Format('yyyy-MM-dd hh:mm:ss');
            html.push('<tr>');
            html.push('<td class="center"><span class="label label-sm label-' + className+ '">'+ op + '</span></td>');
            html.push('<td class="center">' + oflowers + '</td>');
            html.push('<td class="center">' + flowers + '</td>');
            html.push('<td class="center">' + nflowers + '</td>');
            html.push('<td class="center">' + created + '</td>');
            html.push('<td class="center">' + message + '</td>');
            html.push('</tr>');
          }
          dTr.next().find('td > div').fadeOut(200, function() {
            var dEl = $(html.join(''));
            var v = data.v ? data.v : '';
            var scp = data.scp ? data.scp : '';
            var ucp = data.ucp ? data.ucp : '';
            var u = 'javascript:funcLoadStatistic(\'' + id +'\' , \'' + pageUrl + '\', {}, 1)';
            $($(this).closest('tbody').html(dEl))
                .closest('section').find('table')
                .after('<div class="pull-right">' + LIVE.util.pagination(count, rows, page, u) + '</div>');
            dEl.fadeIn(200);
          });
        } else {
          dTr.next().find('td > div').html('<span class="color-red"><i class="icon-remove-circle"></i> 找不到符合条件的记录 <a href="javascript:void(0)">重新加载</a></span>')
              .find('a').click(function(e) {
            e.preventDefault();
            funcLoad(ajaxUrl);
          });
        }
    }).fail(function() {
      dTr.next().find('td > div').html('<span class="color-red"><i class="icon-remove-circle"></i> 数据加载失败，请 <a href="javascript:void(0)">重新加载</a></span>')
          .find('a').click(function(e) {
        e.preventDefault();
        funcLoad(ajaxUrl);
      });
    }).always(function() {
      expandedId = id;
      loading = false;
    });
  };
  funcLoad(ajaxUrl);
};

$('#table > tbody').delegate('.show-details', 'click', function(e) {
  e.preventDefault();
  console.log(11);
  let _this = $(this), tr = _this.closest('tr'), playerid = tr.attr('data-id');
  funcLoadStatistic(playerid, '{url("admin/player/flowerLog/")}' + playerid, {});
});





console.log(1);
</script>